<%@ page language="java" pageEncoding="UTF-8"%>
<script type="text/javascript">
	var paperDatagrid;
	var paperStudentDatagrid;
	$(function() {
		paperDatagrid = $('#student_paperList_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/paperAction!queryPaper.action',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20 ],
			checkOnSelect : true,
			selectOnCheck : true,
			singleSelect : true,
			striped : true,
			columns : [ [ {
				field : 'id',
				title : '编号',
				width : 80,
				checkbox : true
			}, {
				field : 'studentName',
				title : '姓名',
				width : 80,
				align : 'left'
			}, {
				field : 'studentNo',
				title : '学号',
				width : 80,
				align : 'left'
			}, {
				field : 'paperTitle',
				title : '论文题目',
				width : 150,
				align : 'left'
			}, {
				field : 'evaluation',
				title : '论文评估情况',
				width : 150,
				align : 'left'
			}, {
				field : 'memo',
				title : '备注',
				width : 150,
				align : 'left',
			} ] ],
			toolbar : [ {
				text : '查询',
				iconCls : 'icon-search',
				handler : function() {
					queryPaper();
				}
			}, '-', {
				text : '增加',
				iconCls : 'icon-add',
				handler : function() {
					addPaper();
				}
			}, '-', {
				text : '修改',
				iconCls : 'icon-edit',
				handler : function() {
					editPaper();
				}
			}, '-', {
				text : '删除',
				iconCls : 'icon-remove',
				handler : function() {
					removePaper();
				}
			} ]
		});

		$('.datagrid-header div').css({
			'textAlign' : 'center'
		});
		
		function queryPaper() {
			$('#student_paperList_queryForm input').val('');
			$('#student_paperList_queryDialog').dialog('open');
		}

		function addPaper() {
			$('#student_paperAdd_addPaperForm input').val('');
			var dlg = $('<div style="padding:10px;" />').dialog({
				width : 500,
				height : 350,
				href : '${pageContext.request.contextPath}/pages/student/paperAdd.jsp',
				modal : true,
				title : '论文评估新增',
				buttons : [ {
					text : '保存',
					handler : function() {
						$('#student_paperAdd_addPaperForm').form('submit', {
							url : '${pageContext.request.contextPath}/paperAction!addPaper.action',
							success : function(r) {
								var obj = jQuery.parseJSON(r);
								if (obj.success) {
									paperDatagrid.datagrid('insertRow', {
										index : 0,
										row : obj.obj
									});
									dlg.dialog('close');
								}
								$.messager.show({
									title : '提示',
									msg : obj.msg,
								});
							}
						});
					}
				}, {
					text : '取消',
					handler : function() {
						$('#student_paperAdd_addPaperForm input').val('');
						dlg.dialog('close');
					}
				} ],
				onClose : function() {
					$(this).dialog('destroy');
				}
			});
		}

		function editPaper() {
			var rows = paperDatagrid.datagrid('getChecked');
			if (rows.length == 1) {
				var dlg = $('<div style="padding:10px;" />').dialog({
					width : 500,
					height : 350,
					href : '${pageContext.request.contextPath}/pages/student/paperEdit.jsp',
					modal : true,
					title : '论文评估编辑',
					buttons : [ {
						text : '保存',
						handler : function() {
							$('#student_paperEdit_editPaperForm').form('submit', {
								url : '${pageContext.request.contextPath}/paperAction!editPaper.action',
								success : function(r) {
									var obj = jQuery.parseJSON(r);
									if (obj.success) {
										dlg.dialog('close');
										paperDatagrid.datagrid('updateRow', {
											index : paperDatagrid.datagrid('getRowIndex', rows[0].id),
											row : obj.obj
										});
									}
									$.messager.show({
										title : '提示',
										msg : obj.msg,
									});
								},
								onSubmit : function(r) {
									$('#student_paperEdit_editPaperForm input[name=id]').val(rows[0].id);
								}
							});
						}
					}, {
						text : '取消',
						handler : function() {
							dlg.dialog('close');
						}
					} ],
					onClose : function() {
						$(this).dialog('destroy');
					},
					onLoad : function() {
						$('#student_paperEdit_editPaperForm').form('load', rows[0]);
					}
				});
			} else {
				$.messager.alert('提示', '一次只能修改一条数据！');
			}
		}

		function removePaper() {
			var rows = paperDatagrid.datagrid('getChecked');
			var ids = [];
			if (rows.length > 0) {
				$.messager.confirm('确认', '确定要删除选择的数据吗？', function(r) {
					if (r) {
						for ( var i = 0; i < rows.length; i++) {
							ids.push(rows[i].id);
						}
						$.ajax({
							url : '${pageContext.request.contextPath}/paperAction!removePaper.action',
							data : {
								ids : ids.join(',')
							},
							dataType : 'json',
							success : function(r) {
								paperDatagrid.datagrid('load');
								paperDatagrid.datagrid('unselectAll');
								$.messager.show({
									title : '提示',
									msg : r.msg,
								});
							}
						});
					}
				});
			} else {
				$.messager.alert('提示', '请选择要删除的记录！');
			}
		}

	});

	function openStudentDialog() {
		$('#student_paperList_studentDialog').dialog('open');
		paperStudentDatagrid = $('#student_paperList_studentDatagrid').datagrid({
			url : '${pageContext.request.contextPath}/studentAction!queryStudent.action',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			striped : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10 ],
			sortName : 'studentName',
			sortOrder : 'asc',
			checkOnSelect : true,
			selectOnCheck : true,
			singleSelect : true,
			columns : [ [ {
				field : 'id',
				title : '编号',
				width : 50,
				checkbox : true
			}, {
				field : 'studentName',
				title : '姓名',
				width : 100,
				sortable : true
			}, {
				field : 'studentNo',
				title : '学号',
				width : 100,
				sortable : true
			}, {
				field : 'title',
				title : '职称',
				width : 100,
				align : 'center',
				hidden : true
			}, {
				field : 'corporationName',
				title : '工作单位',
				width : 150,
				align : 'center'
			}, {
				field : 'position',
				title : '职务',
				width : 100,
				align : 'center'
			}, {
				field : 'mobile',
				title : '手机',
				width : 100,
				align : 'center'
			}, {
				field : 'QQ',
				title : 'qq',
				width : 100,
				align : 'center'
			}, {
				field : 'email',
				title : '电子邮件',
				width : 100,
				align : 'center'
			} ] ],
			toolbar : '#student_paperList_studentToolbar',
			onDblClickRow : function(rowIndex, rowData) {
				$('#student_paperAdd_addPaperForm input[name=studentName]').val(rowData.studentName);
				$('#student_paperAdd_addPaperForm input[name=studentNo]').val(rowData.studentNo);
				$('#student_paperAdd_addPaperForm input[name=studentId]').val(rowData.id);
				$('#student_paperList_studentDialog').dialog('close');
			}
		});
		paperStudentDatagrid.datagrid('unselectAll');
		paperStudentDatagrid.datagrid('uncheckAll');
	}

	function queryPaperList() {
		paperStudentDatagrid.datagrid('load', serializeObject($('#student_paperList_queryStudentForm')));
	}
</script>
<div id="student_paperList_layout" class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false">
		<table id="student_paperList_datagrid"></table>
	</div>
</div>
<div id="student_paperList_queryDialog" class="easyui-dialog" data-options="title:'学生查询',closed:true,modal:true,
			buttons:[{
				text : '查询',
				handler : function(){
					$('#student_paperList_datagrid').datagrid('load', serializeObject($('#student_paperList_queryForm')));
				    $('#student_paperList_queryDialog').dialog('close');
				}
			},{
				text : '清空',
				handler : function(){
					$('#student_paperList_queryForm input').val('');
				}
			}]" style="width:400px;height:200px;padding:20px 20px;" align="center">
	<form id="student_paperList_queryForm" method="post">
		<table>
			<tr>
				<td style="text-align: right;">姓名：</td>
				<td><input name="studentName" style="width: 240px;" /></td>
			</tr>
			<tr>
				<td style="text-align: right;">学号：</td>
				<td><input name="studentNo" style="width: 240px;" /></td>
			</tr>
			<tr>
				<td style="text-align: right;">论文题目：</td>
				<td><input name="paperTitle" style="width: 240px;" /></td>
			</tr>
		</table>
	</form>
</div>
<div id="student_paperList_studentDialog" class="easyui-dialog" data-options="title:'学生查询',closed:true,modal:true" style="width:800px;height:500px;">
	<div id="student_paperList_studentLayout" class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'center',border:false">
			<table id="student_paperList_studentDatagrid"></table>
		</div>
	</div>
</div>
<div id="student_paperList_studentToolbar" style="height:60px;padding:5px 0 0 20px;">
	<form id="student_paperList_queryStudentForm" method="post">
		<table>
			<tr>
				<td style="text-align: right;">姓名：</td>
				<td><input name="studentName" style="width:200px;" /></td>
			</tr>
			<tr>
				<td style="text-align: right;">学号：</td>
				<td><input name="studentNo" style="width:200px;" />&nbsp;&nbsp; <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="queryPaperList()">查询</a></td>
			</tr>
		</table>
	</form>
</div>